import java.util.Arrays;

public class Solution1608 {
    public int specialArray(int[] nums) {
        Arrays.sort(nums);
        for (int i=nums.length-1;i>=0;i--){
            int t=nums.length-i;
            if (nums[i]>=t && (i>=1 && nums[i-1]<t || i==0)){
                return t;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1608().specialArray(new int[]{3,5}));
    }
}
